/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2007 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   Beagle/IntVec/Package.cpp
 *  \brief  Source code of class IntVec::Package.
 *  \author Christian Gagne
 *  $Revision: 1.4 $
 *  $Date: 2007/09/17 17:25:49 $
 */

#include "Beagle/IntVec.hpp"

using namespace Beagle;


/*!
 *  \brief Construct package with integer vector objects.
 *  \param inInitSize Size of vectors generated by initialization.
 */
IntVec::Package::Package(unsigned int inInitSize) :
		PackageAbstract("IntVec-Package"),
		mInitSize(inInitSize)
{ }


/*!
 *  \brief Configure system by adding necessary components into it.
 *  \param ioSystem System to configure.
 */
void IntVec::Package::configure(System& ioSystem)
{
	Beagle_StackTraceBeginM();
	Factory& lFactory = ioSystem.getFactory();

	// Add available basic types to the factory
	lFactory.insertAllocator("Beagle::IntVec::CrossoverCycleOp", new IntVec::CrossoverCycleOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverIndicesOp", new IntVec::CrossoverIndicesOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverNonAbelOp", new IntVec::CrossoverNonAbelOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverNWOXOp", new IntVec::CrossoverNWOXOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverOnePointOp", new IntVec::CrossoverOnePointOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverOrderedOp", new IntVec::CrossoverOrderedOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverPMXOp", new IntVec::CrossoverPMXOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverTwoPointsOp", new IntVec::CrossoverTwoPointsOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverUniformOp", new IntVec::CrossoverUniformOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::CrossoverUPMXOp", new IntVec::CrossoverUPMXOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::InitIndicesOp", new IntVec::InitIndicesOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::InitializationOp", new IntVec::InitializationOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::InitializationQROp", new IntVec::InitializationQROp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::IntegerVector", new IntVec::IntegerVector::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationMoveSequenceOp", new IntVec::MutationMoveSequenceOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationUniformQROp", new IntVec::MutationUniformQROp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationReverseSequenceOp", new IntVec::MutationReverseSequenceOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationShuffleOp", new IntVec::MutationShuffleOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationShuffleSequenceOp", new IntVec::MutationShuffleSequenceOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::MutationUniformOp", new IntVec::MutationUniformOp::Alloc);
	lFactory.insertAllocator("Beagle::IntVec::Package", new IntVec::Package::Alloc);

	// Aliases to short name of operators
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverCycleOp", "IntVec-CrossoverCycleOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverIndicesOp", "IntVec-CrossoverIndicesOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverNonAbelOp", "IntVec-CrossoverNonAbelOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverNWOXOp", "IntVec-CrossoverNWOXOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverOnePointOp", "IntVec-CrossoverOnePointOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverOrderedOp", "IntVec-CrossoverOrderedOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverPMXOp", "IntVec-CrossoverPMXOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverTwoPointsOp", "IntVec-CrossoverTwoPointsOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverUniformOp", "IntVec-CrossoverUniformOp");
	lFactory.aliasAllocator("Beagle::IntVec::CrossoverUPMXOp", "IntVec-CrossoverUPMXOp");
	lFactory.aliasAllocator("Beagle::IntVec::InitIndicesOp", "IntVec-InitIndicesOp");
	lFactory.aliasAllocator("Beagle::IntVec::InitializationOp", "IntVec-InitializationOp");
	lFactory.aliasAllocator("Beagle::IntVec::InitializationQROp", "IntVec-InitializationQROp");
	lFactory.aliasAllocator("Beagle::IntVec::IntegerVector", "IntVec-IntegerVector");
	lFactory.aliasAllocator("Beagle::IntVec::MutationMoveSequenceOp", "IntVec-MutationMoveSequenceOp");
	lFactory.aliasAllocator("Beagle::IntVec::MutationUniformQROp", "IntVec-MutationUniformQROp");
	lFactory.aliasAllocator("Beagle::IntVec::MutationReverseSequenceOp", "IntVec-MutationReverseSequenceOp");
	lFactory.aliasAllocator("Beagle::IntVec::MutationShuffleOp", "IntVec-MutationShuffleOp");
	lFactory.aliasAllocator("Beagle::IntVec::MutationShuffleSequenceOp", "IntVec-MutationShuffleSequenceOp");
	lFactory.aliasAllocator("Beagle::IntVec::MutationUniformOp", "IntVec-MutationUniformOp");
	lFactory.aliasAllocator("Beagle::IntVec::Package", "IntVec-Package");

	// Set some basic concept-type associations in factory
	lFactory.setConcept("CrossoverOp", "IntVec-CrossoverUniformOp");
	lFactory.setConcept("Genotype", "IntVec-IntegerVector");
	lFactory.setConcept("InitializationOp", "IntVec-InitializationOp");
	lFactory.setConcept("MutationOp", "IntVec-MutationUniformOp");

	// Add components
	if(ioSystem.haveComponent("QuasiRandom") == NULL) {
		ioSystem.addComponent(new QuasiRandom);
	}

	// Set default initialization size
	ioSystem.getRegister().setEntryDefaultValue("intvec.init.vectorsize",
	        new UInt(mInitSize),
	        uint2str(mInitSize));

	Beagle_StackTraceEndM();
}


/*!
 *  \brief List packages which current package depends.
 *  \return Bag with the packages instanciation on which current package depends.
 *
 *  Package depends on Beagle::Package and Beagle::EC::Package.
 */
PackageAbstract::Bag IntVec::Package::listDependencies(void)
{
	Beagle_StackTraceBeginM();
	PackageAbstract::Bag lDependencies;
	lDependencies.push_back(new Beagle::Package());
	lDependencies.push_back(new Beagle::EC::Package());
	return lDependencies;
	Beagle_StackTraceEndM();
}
